package com.ikas.ai.server.schedule.handler;

import com.ikas.ai.server.module.condition.service.WorkFlowInstanceResultService;
import com.ikas.ai.server.module.steady.service.SteadyStateMeteService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author hu.bowei@ikasinfo.com
 * @date 2023-11-06- 11:02
 * 机组启停次数统计
 */
@Component
@Slf4j
public class WorkFlowInstanceHandler {

    @Autowired
    private WorkFlowInstanceResultService workFlowInstanceResultService;
    @Autowired
    private SteadyStateMeteService steadyStateMeteService;

    /**
     * 驾驶舱首页工况启动次数和运行时长统计
     * 每日0点执行
     */
    @XxlJob(value = "syncWorkFlowInstanceResult")
    public void syncWorkFlowInstanceResult() {
        log.info("===================>xxl-job syncWorkFlowInstanceResultTask start<===================");
        workFlowInstanceResultService.syncWorkFlowInstanceResult();
        log.info("===================>xxl-job syncWorkFlowInstanceResultTask end<===================");
    }

    /**
     * 更新处于进程中的instance，防止服务异常工况没有结束
     * 定时任务定期查询 2小时(可配置)查询状态为0的数据，用创建时间和当前时间做比较，如果大于12小时(可配置)，
     * 则直接更新这条数据的状态为2，desc="超过12小时(可配置)，未结束，自动修改为状态为已完成"。updateTime=now; endTime=now()
     */
    @XxlJob(value = "updateWorkFlowInstance")
    public void updateWorkFlowInstance() {
        log.info("===================>xxl-job updateWorkFlowInstance start<===================");
        workFlowInstanceResultService.updateWorkFlowInstance();
        log.info("===================>xxl-job updateWorkFlowInstance end<===================");
    }

    /**
     * 定时任务频率：每个小时更新
     * 停机稳态表的稳态测点超过24个小时的
     */
    @XxlJob(value = "updateSteadyStateMete")
    public void updateSteadyStateMete() {
        log.info("===================>xxl-job updateSteadyStateMete start<===================");
        steadyStateMeteService.updateSteadyStateMete();
        log.info("===================>xxl-job updateSteadyStateMete end<===================");
    }
}
